package m202401.d08;

/**
 * @@author: 爱做梦的锤子
 * @date: 2024/1/8 09:47
 */
//100. 相同的树
public class Q100 {
    public boolean isSameTree(TreeNode p, TreeNode q) {
        if (!isSameNode(p, q)) {
            return false;
        }
        if (p == null && q == null) {
            return true;
        }
        return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
    }

    public boolean isSameNode(TreeNode p, TreeNode q) {
        if (p != null && q != null) {
            return p.val == q.val;
        }
        return p == null && q == null;
    }

    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
}
